package com.stand.hardcode.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stand.hardcode.entity.StandUser;
import com.stand.hardcode.manager.UserManager;
import com.stand.hardcode.util.RequestAttributes;

//profile
public class DeleteAccountServlet extends HttpServlet{

		public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
			try {
				req.getRequestDispatcher("confirmdelete.jsp").forward(req, resp);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
			if(UserManager.IsLoggedIn(req)){
				StandUser u = (StandUser)req.getSession().getAttribute(RequestAttributes.CURRENT_USER);
				
				//Perform all the clearing up
				UserManager.DeleteUser(u);
				
				//delete wishlist? items?
				
				try {
					req.getSession().invalidate();
					req.getRequestDispatcher("deleted.jsp").forward(req, resp);
				} catch (ServletException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
				
		}

}
